﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App1AppHandler;

namespace Reborn_Server.App1AppHandler
{
    public class Spell_PoisonDagger : TargetSpell
    {
        public void Cast(CreatureBase myCharacter, int CastLevel, long CreatureGUID)
        {
            Weapon daggerToPoison = null;
            if (myCharacter.RightHand != null && myCharacter.RightHand is Weapon)
            {
                Weapon weapon = (Weapon)myCharacter.RightHand;
                if (weapon.Skill == "Piercing_1H" && weapon.WeaponEffect == null)
                    daggerToPoison = weapon;
            }
            if (daggerToPoison == null && myCharacter.LeftHand != null && myCharacter.LeftHand is Weapon)
            {
                Weapon weapon = (Weapon)myCharacter.LeftHand;
                if (weapon.Skill == "Piercing_1H" && weapon.WeaponEffect == null)
                    daggerToPoison = weapon;
            }
            if (daggerToPoison == null)
            {
                if (myCharacter is Character)
                {
                    Character character = (Character)myCharacter;

                    Message msg = new Message();
                    msg.CreatureID = character.CreatureID;
                    msg.Type = "server";
                    msg.Text = "Cannot find a weapon to poison";

                    character.PlaySound("Ding", character.MapX, character.MapY);
                    character.AddMessage(msg);
                    character.SetBusy(false);
                }
                return;
            }

            List<MapItem> MapItemsWithin12;
            if (base.InitializeCast(myCharacter, CastLevel, myCharacter.CreatureID, false, out MapItemsWithin12) == false)
                return;

            
            daggerToPoison.WeaponEffect = spellIcon;
            daggerToPoison.WeaponEffectLevel = CastingCreatureLevel;
            daggerToPoison.WeaponEffectInt = CastingCreatureInt;
            daggerToPoison.WeaponEffectWis = CastingCreatureWis;

            TargetCreatureBase.Update_Character();
            if (TargetCreatureBase is Character)
            {
                Character character = (Character)TargetCreatureBase;
                Message msg = new Message();
                msg.CreatureID = character.CreatureID;
                msg.Type = "spelldefense";
                msg.Text = "You cast poison on " + daggerToPoison.Name;

                character.AddMessage(msg);
            }

            foreach (MapItem mapitem in MapItemsWithin12)
            {
                if (Math.Abs(mapitem.MapX - TargetCreatureBase.MapX) <= 4 && Math.Abs(mapitem.MapY - TargetCreatureBase.MapY) <= 4)
                {
                    foreach (CreatureBase creatureBase in mapitem.CreaturesBases)
                    {
                        if (creatureBase is Character)
                        {
                            Character character = (Character)creatureBase;
                            character.AddCreatureBase(TargetCreatureBase);
                        }
                    }
                }
            }
        }
    }
}
